//
//  HSLotteryBallCell.m
//  HolyShit
//
//  Created by Robin on 2017/4/30.
//  Copyright © 2017年 HolyShit. All rights reserved.
//

#import "HSLotteryBallCell.h"

@implementation HSLotteryBallModel

@end


@interface HSLotteryBallCell ()

@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UIImageView *iconImgV;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *scoreLb;

@end

@implementation HSLotteryBallCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    self.backgroundColor = WHITE_COLOR;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.width = ScreenWidth;
    self.nameLb = [UILabel labelWithFont:MYFont(Font32) color:HEXCOLOR(HSColorBlack)];
    [self addSubview:self.nameLb];
    self.timeLb = [UILabel labelWithFont:MYFont(Font26) color:HEXCOLOR(HSColorGray)];
    [self addSubview:self.timeLb];
    UILabel *arrowLb = [UILabel labelWithFrame:CGRectZero font:IconFont(20) color:HEXCOLOR(HSColorGray) text:@""];
    [self addSubview:arrowLb];
    self.iconImgV = [UIImageView new];
    self.iconImgV.layer.borderWidth = 3;
    [self addSubview:self.iconImgV];
    self.bgView = [UIView new];
    [self addSubview:self.bgView];
    self.scoreLb = [UILabel labelWithFont:MYFont(Font28) color:WHITE_COLOR];
    [self addSubview:self.scoreLb];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(15);
    }];
    
    [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLb.mas_right).offset(7);
        make.bottom.equalTo(self.nameLb);
    }];
    
    [arrowLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-20);
    }];
    
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLb);
        make.top.equalTo(self.nameLb.mas_bottom).offset(20);
        make.width.height.mas_equalTo(35);
    }];
    self.iconImgV.layer.cornerRadius = 17.5;
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImgV.mas_right).offset(-14) ;
        make.right.mas_equalTo(-60);
        make.centerY.equalTo(self.iconImgV);
        make.height.mas_equalTo(24);
    }];
    self.bgView.layer.cornerRadius = 12;
    
    [self.bgView addSubview:self.scoreLb];
    self.scoreLb.textAlignment = NSTextAlignmentCenter;
    [self.scoreLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    [self bringSubviewToFront:self.iconImgV];
    
    [self showLineForDirection:MYDirectionBottom leftPad:15];
}

- (void)setModel:(HSLotteryBallModel *)model
{
    _model = model;
    self.nameLb.text = model.lot_name;
    self.timeLb.text = model.match_time;
    self.scoreLb.text = [NSString stringWithFormat:@"%@ %@ %@", model.home_team, model.score, model.guest_team];
    if ([model.lot_name hasSuffix:@"足球"]) {
        self.iconImgV.image = [UIImage imageNamed:@"zuqiu"];
        self.iconImgV.layer.borderColor = HEXCOLOR(HSColorGreen).CGColor;
        self.bgView.backgroundColor = HEXCOLOR(HSColorGreen);
    }
    else{
        self.iconImgV.image = [UIImage imageNamed:@"lanqiu"];
        self.iconImgV.layer.borderColor = HEXCOLOR(HSColorRed).CGColor;
        self.bgView.backgroundColor = HEXCOLOR(HSColorRed);
    }
}

@end
